/*
 * @FilePath: /my-map-demo/src/views/layer-management/point-markers/config/line-config.js
 * @Author: 张文鑫
 * @Date: 2024-12-02 11:09:11
 * @Description: 
 */
import { Vector as VectorLayer } from "ol/layer";
import { Vector as VectorSource } from "ol/source";
import { Style, Stroke, Fill } from "ol/style";
import { GeoJSON } from "ol/format";

import geoJsonDataNingbo from "../data/ningbo.json";
import { hangzhou } from "../../common/hangzhouAll.js";

// 创建 GeoJSON 实例
const geoJSON = new GeoJSON();

// 解析杭州数据
const featuresHangzhou = geoJSON.readFeatures(hangzhou, {
  dataProjection: "EPSG:4326",
  featureProjection: "EPSG:4326",
});

// 解析宁波数据
const featuresNingbo = geoJSON.readFeatures(geoJsonDataNingbo, {
  dataProjection: "EPSG:4326",
  featureProjection: "EPSG:4326",
});

// 设置不同的样式
const polygonStyleHangzhou = new Style({
  stroke: new Stroke({
    color: "#FF0000", // 红色边框
    width: 4,
  }),
  fill: new Fill({
    color: "rgba(255, 0, 0, 0.1)", // 半透明红色填充
  }),
});

const polygonStyleNingbo = new Style({
  stroke: new Stroke({
    color: "#0000FF", // 蓝色边框
    width: 4,
  }),
  fill: new Fill({
    color: "rgba(0, 0, 255, 0.1)", // 半透明蓝色填充
  }),
});

// 添加特征并设置样式
featuresHangzhou.forEach((feature) => {
  feature.setStyle(polygonStyleHangzhou);
});

featuresNingbo.forEach((feature) => {
  feature.setStyle(polygonStyleNingbo);
});

// 创建矢量图层
const vectorSourceAll = new VectorSource();
vectorSourceAll.addFeatures([...featuresHangzhou, ...featuresNingbo]);

// 创建矢量图层
export const lineLayerAll = new VectorLayer({
  source: vectorSourceAll,
  zIndex: 3,
});
